//
//  LGVisitorView.m
//  微博oc版
//
//  Created by Apple_Lzzy27 on 16/10/12.
//  Copyright © 2016年 Apple_Lzzy27. All rights reserved.
//

#import "LGVisitorView.h"

@interface LGVisitorView()
@property (nonatomic,weak) CABasicAnimation *animati;
@end

@implementation LGVisitorView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setUI];
        
    }
    
    return self;
}


//动态添加访客视图
- (void)setVisitorDict:(NSDictionary *)visitorDict{
    _visitorDict = visitorDict;
 
    if ([visitorDict[@"icon"]  isEqual: @""]) {
        [self setAnimation];
       
        return;
    }
    self.housView.hidden = YES;
    self.coverView.hidden = YES;
    [self.iconView.layer removeAllAnimations];
    self.tipLable.text = visitorDict[@"text"];
    NSLog(@"%@",self.tipLable.text);
    self.iconView.image = [UIImage imageNamed:visitorDict[@"icon"]];
    
    
    
    
}


//背景旋转图
- (UIImageView *)iconView{
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];

    }
    
    return _iconView;
}
//半透明遮盖图
- (UIImageView *)coverView{
    if (_coverView == nil) {
        _coverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    
    return _coverView;
}
//小房子
- (UIImageView *)housView{
    
    if (_housView == nil) {
        _housView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _housView;
    
}
//文字
- (UILabel *)tipLable{
    
    if (_tipLable == nil) {
        _tipLable = [[UILabel  alloc] init];
        _tipLable.text = @"关注一些人, 看看有什么惊喜 关注一些人, 看看有什么惊喜";
        _tipLable.numberOfLines = 0;
        _tipLable.textAlignment = NSTextAlignmentCenter;
        _tipLable.font = [UIFont boldSystemFontOfSize:13];
        _tipLable.textColor = [UIColor darkGrayColor];
    }
    return _tipLable;
}
//登录按钮
- (UIButton *)logButton{
    if (_logButton == nil) {
        
        _logButton = [UIButton cz_textButton:@"登录" fontSize:14 normalColor:[UIColor orangeColor] highlightedColor:[UIColor darkGrayColor] backgroundImageName:@"common_button_white_disable"];
       
        
    }
    
    return _logButton;
}
//注册按钮
- (UIButton *)regiButton{
    if (_regiButton == nil) {
        _regiButton = [UIButton cz_textButton:@"注册" fontSize:14 normalColor:[UIColor orangeColor] highlightedColor:[UIColor darkGrayColor] backgroundImageName:@"common_button_white_disable"];

    }
    
    return _regiButton;
}
//添加控件到视图
- (void)setUI{
    [self addSubview:self.iconView];
    [self addSubview:self.coverView];
    [self addSubview:self.housView];
    [self addSubview:self.tipLable];
    [self addSubview:self.logButton];
    [self addSubview:self.regiButton];
    [self setUIFrame];
    self.backgroundColor = [UIColor cz_colorWithHex:0xEDEDED];
    //self.backgroundColor = [UIColor grayColor];
}
//动画旋转
- (void)setAnimation{
    
    CABasicAnimation *animati = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animati.toValue = @(M_PI * 2);
    animati.repeatCount = MAXFLOAT;
    animati.duration = 15;
    animati.removedOnCompletion = NO;
    [self.iconView.layer addAnimation:animati forKey:nil];
    self.animati = animati;
}



- (void)setUIFrame{
    //防止循环引用
     __weak typeof(self) weakSelf = self;
    //转圈图
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf);
        make.centerY.offset(-60);
        
    }];
    //小房子图
    [self.housView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf.iconView);
        
    }];
    //半透明图片
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 0, 200, 0));
        
    }];
    [self.tipLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(weakSelf.iconView.mas_bottom).with.offset(10);
        make.centerX.equalTo(weakSelf);
        make.width.mas_equalTo(@265);
    }];
    
    //登录按钮约束
    [self.logButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.top.equalTo(weakSelf.iconView.mas_bottom).with.offset(50);
        
        make.left.equalTo(weakSelf.mas_left).with.offset(20);
        make.right.equalTo(weakSelf.regiButton.mas_left).with.offset(-20);
        make.width.equalTo(weakSelf.regiButton);
    }];
    //注册按钮约束
    [self.regiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.centerY.equalTo(weakSelf.logButton);
        make.left.equalTo(weakSelf.logButton.mas_right).with.offset(20);
        make.right.equalTo(weakSelf.mas_right).with.offset(-20);
        make.width.equalTo(weakSelf.logButton);
        
    }];
 
    
}
@end
